//
//  InstalDetailVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/23.
//  Copyright © 2020 tym. All rights reserved.
//

#import "InstalDetailVC.h"
#import "UIView+ZFFrame.h"
#import "Sizes.h"
#import "MagicImageView.h"
#import "EquipmentService.h"
#import "UIImageView+YPImage.h"

@interface InstalDetailVC ()

@property(nonatomic,copy) EquipmentService *services;

@property(nonatomic,strong) UIScrollView  *scrollView;

@property(nonatomic,weak) IBOutlet  UIView *stateView;
@property(nonatomic,weak) IBOutlet  UILabel *stateLab;
@property(nonatomic,weak) IBOutlet  UILabel *orderLab;
@property(nonatomic,weak) IBOutlet  UILabel *timeLab;


@property(nonatomic,weak) IBOutlet  UIView *infoView;
@property(nonatomic,weak) IBOutlet  UILabel *contactsLab;
@property(nonatomic,weak) IBOutlet  UILabel *mobileLab;
@property(nonatomic,weak) IBOutlet  UILabel *locationLab;
@property(nonatomic,weak) IBOutlet  UILabel *addressLab;

@property(nonatomic,weak) IBOutlet UIView *productView;
@property(nonatomic,weak) IBOutlet  UILabel *modelLab;
@property(nonatomic,weak) IBOutlet  UILabel *colorLab;
@property(nonatomic,weak) IBOutlet  UILabel *caizhiLab;
@property(nonatomic,weak) IBOutlet  UILabel *tiandiLab;
@property(nonatomic,weak) IBOutlet  UILabel *fangxiangLab;

@property(nonatomic,weak) IBOutlet UIView *doorView;
@property(nonatomic,weak) IBOutlet  UILabel *houLab;
@property(nonatomic,weak) IBOutlet  UILabel *guigeLab;
@property(nonatomic,weak) IBOutlet  UILabel *chicunLab;
@property(nonatomic,weak) IBOutlet  MagicImageView *image1;
@property(nonatomic,weak) IBOutlet  MagicImageView *image2;
@property(nonatomic,weak) IBOutlet  MagicImageView *image3;


@property(nonatomic,weak) IBOutlet UIView *bottomView;
@property(nonatomic,weak) IBOutlet UIButton *cancelBtn;

@property(nonatomic,strong) RepairsApplyModel *repairModel;
@end

@implementation InstalDetailVC

-(instancetype)initWithRepairModel:(RepairsApplyModel*)model{
    self = [super init];
    if (self) {
        self.repairModel = model;
    }
    return self;
}

-(EquipmentService*)services{
    if (_services == nil) {
        _services = [[EquipmentService alloc] init];
    }
    return _services;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"预约详情"];
    _scrollView  = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-NavigateonHeight-SafeBottomMargin)];
    [self.view addSubview:_scrollView];
    
    _stateView.frame = CGRectMake(0, 0, ScreenWidth, _stateView.zf_height);
    [self.scrollView addSubview:_stateView];
    
    _infoView.frame = CGRectMake(0, _stateView.zf_bottom, ScreenWidth, _infoView.zf_height);
    [self.scrollView addSubview:_infoView];
    
    _productView.frame = CGRectMake(0,_infoView.zf_bottom, ScreenWidth, _productView.zf_height);
    [self.scrollView addSubview:_productView];
    
    _doorView.frame = CGRectMake(0, _productView.zf_bottom, ScreenWidth, _doorView.zf_height);
    [self.scrollView addSubview:_doorView];
    
    _bottomView.frame = CGRectMake(0, _doorView.zf_bottom, ScreenWidth, _bottomView.zf_height);
    [self.scrollView addSubview:_bottomView];
    
    self.scrollView.contentSize = CGSizeMake(ScreenWidth, _bottomView.zf_bottom);
    
    [self setUIData];
}

-(void)setUIData{
    self.stateLab.text = [self.repairModel getStatusStr];
    self.timeLab.text = self.repairModel.createTime;
    
    self.contactsLab.text = self.repairModel.contacts;
    self.mobileLab.text = self.repairModel.mobile;
    self.locationLab.text = [NSString stringWithFormat:@"%@%@%@",self.repairModel.province?self.repairModel.province:@"",self.repairModel.city?self.repairModel.city:@"",self.repairModel.district];
    self.addressLab.text = self.repairModel.address;
    
    self.modelLab.text = self.repairModel.productModel;
    self.colorLab.text = self.repairModel.productColor;
    
    if (self.repairModel.doorModel == 1) {
        self.caizhiLab.text = @"木门";
    }else if (self.repairModel.doorModel == 2){
        self.caizhiLab.text = @"不锈钢门";
    }
    
    if (self.repairModel.heavenEarthHook == 1) {
        self.tiandiLab.text = @"有";
    }else if (self.repairModel.heavenEarthHook == 2){
        self.tiandiLab.text = @"无";
    }
    self.fangxiangLab.text = [self.repairModel openDirectionStr];
    
    self.houLab.text = [NSString stringWithFormat:@"%.1f毫米",self.repairModel.doorThickness ];
    self.guigeLab.text = [self.repairModel guideVaneSpecificationStr];
    
    if(self.repairModel.guideVaneWide>0){
        self.chicunLab.text = [NSString stringWithFormat:@"宽%ld毫米,长%ld毫米",self.repairModel.guideVaneWide,_repairModel.guideVaneLength];
    }else{
        self.chicunLab.text = @"";
    }
    
    [self.image1 yp_setImageUlr:[NSString stringWithFormat:@"%@%@",BaseImageUrl,self.repairModel.imgUrl1]];
    [self.image2 yp_setImageUlr:[NSString stringWithFormat:@"%@%@",BaseImageUrl,self.repairModel.imgUrl2]];
    [self.image3 yp_setImageUlr:[NSString stringWithFormat:@"%@%@",BaseImageUrl,self.repairModel.imgUrl3]];
    
    if (self.repairModel.status == 9) {
        [self.bottomView removeFromSuperview];
    }
}

-(IBAction)cancelOrderAction:(id)sender{
    
    [self.services getcancelEquipmentsubscribeinstallapplyID:self.repairModel.id  completion:^(LMJBaseResponse * _Nonnull respons) {
        if (respons.message) {
            [WHToast showMessage:respons.message duration:2 finishHandler:nil];
        }else{
            [WHToast showMessage:@"取消成功" duration:2 finishHandler:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
